package cn.christ.com.mobilesafe.view.activity_splash;

import android.Manifest;
import android.support.annotation.NonNull;
import android.widget.TextView;

import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.PermissionListener;

import java.util.List;

import butterknife.BindView;
import cn.christ.com.mobilesafe.MyApp;
import cn.christ.com.mobilesafe.R;
import cn.christ.com.mobilesafe.common.BaseActivity;
import cn.christ.com.mobilesafe.constant.Constants;
import cn.christ.com.mobilesafe.view.activity_main.MainActivity;

/**
 * Created by Christ on 2018/7/13.
 * splashActivity界面
 */

public class SplashActivity extends BaseActivity {
    @BindView(R.id.tv_splash_version)
    TextView mTvSplashVersion;

    private IFlashActivityPresenter mPresenter;


    @Override
    public int getLayoutRes() {
        return R.layout.activity_splash;
    }

    @Override
    public void initPresenter() {
        mPresenter = new FlashActivityPresenter();
    }

    @Override
    public void initListener() {

    }

    private String url = "http://192.168.1.109:8080/mobilesafe/mobilesafe2.0.apk";

    @Override
    public void initData() {
        //startActivity(MainActivity.class);
        //适配6.0系统
        AndPermission.with(getApplicationContext())
                .requestCode(Constants.READ_EXTERNAL_STORAGE)
                .permission(Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.RECEIVE_BOOT_COMPLETED,
                        Manifest.permission.SEND_SMS,
                        Manifest.permission.RECEIVE_SMS,
                        Manifest.permission.ACCESS_FINE_LOCATION,
                        Manifest.permission.KILL_BACKGROUND_PROCESSES
                )
                .callback(new PermissionListener() {
                    @Override
                    public void onSucceed(int requestCode, @NonNull List<String> grantPermissions) {
                        if (Constants.READ_EXTERNAL_STORAGE == requestCode) {
                            //UpdateService.Builder.create(url).build(getApplicationContext());
                        }
                    }

                    @Override
                    public void onFailed(int requestCode, @NonNull List<String> deniedPermissions) {
                        if (AndPermission.hasAlwaysDeniedPermission(SplashActivity.this, deniedPermissions)) {
                            AndPermission.defaultSettingDialog(SplashActivity.this, Constants.READ_EXTERNAL_STORAGE).show();
                        }
                    }
                })
                .start();
        MyApp.handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(MainActivity.class);
            }
        }, 100);
        //startActivity(MainActivity.class);

    }


}
